/* 
 * File:   stringHelper.h
 * Author: ferranferri
 *
 * Created on May 6, 2013, 6:33 PM
 */
#pragma once
#ifndef _Z3D_CORE_STRINGHELPER_H
#define	_Z3D_CORE_STRINGHELPER_H

namespace z3d{
    namespace core{
        class StringHelper{
        public:
            /**
             * Returns the substring contained between init and end or empty 
             * if init or end aren't found.
             * @param init The starting substring to find
             * @param end The closing substring to find
             * @return the substring contained between init and end or empty 
             * if init or end aren't found.
             */
            static std::string getSubstr(const char* init, const char* end, const std::string ss)
            {
                
                size_t p1 = ss.find(init);
                if(p1 == std::string::npos)
                {
                    return "";
                }
                p1 += std::string(init).length();
                
                if(std::string(end).length() == 0)
                {
                    return ss.substr(p1);
                }
                size_t p2 = ss.find(end, p1);
                if(p2 == std::string::npos)
                {
                    return "";
                }
                return ss.substr(p1, p2 - p1);
            }
        };
    }
}

#endif	/* _Z3D_CORE_STRINGHELPER_H */

